﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WX.WMS.DataModel;

namespace WX.WMS.BLL
{
    public class VOutStockItemGroup : T_OUTSTOCK_ITEM
    {
        private string _StoreName;
        private double _PACKET_QTYCount;
        private double _PACKET_QTY2Count;
        private double _NET_WEIGHTCount;
        private double _GROSS_WEIGHTCount;
        private string _BarCode;
        private string _ProductCode;
        private string _Standard;
        private string _LotNumber;
        private string _SubLotNumber;
        private string _KeyStandard;
        private string _SupplyLotNumber;
        private string _BigClass;
        private string _UnitName1;
        private string _UnitName2; 

        public string StoreName
        {
            get { return this._StoreName; }
            set { this._StoreName = value; }
        }
        public double PACKET_QTY2Count
        {
            get { return this._PACKET_QTY2Count; }
            set { this._PACKET_QTY2Count = value; }
        }
        public double PACKET_QTYCount
        {
            get { return this._PACKET_QTYCount; }
            set { this._PACKET_QTYCount = value; }
        }
        public double NET_WEIGHTCount
        {
            get { return this._NET_WEIGHTCount; }
            set { this._NET_WEIGHTCount = value; }
        }
        public double GROSS_WEIGHTCount
        {
            get { return this._GROSS_WEIGHTCount; }
            set { this._GROSS_WEIGHTCount = value; }
        }
        public string BarCode
        {
            get { return this._BarCode; }
            set { this._BarCode = value; }
        }


        public string ProductCode
        {
            get { return this._ProductCode; }
            set
            {
                this._ProductCode = value;
            }
        }

        public string Standard
        {
            get { return this._Standard; }
            set
            {
                this._Standard = value;
            }
        }

        public string LotNumber
        {
            get { return this._LotNumber; }
            set
            {
                this._LotNumber = value;
            }
        }

        public string SubLotNumber
        {
            get { return this._SubLotNumber; }
            set
            {
                this._SubLotNumber = value;
            }
        }

        public string KeyStandard
        {
            get { return this._KeyStandard; }
            set { this._KeyStandard = value; }
        }

        public string SupplyLotNumber
        {
            get { return this._SupplyLotNumber; }
            set { this._SupplyLotNumber = value; }
        }

        public string BigClass
        {
            get { return this._BigClass; }
            set { this._BigClass = value; }
        }
        public string WeightUnitName
        {
            get { return this._UnitName1; }
            set { this._UnitName1 = value; }
        }
        public string PackUnitName
        {
            get { return this._UnitName2; }
            set
            {
                this._UnitName2 = value;
            }
        }
    }
    public class VOutStockItem : T_OUTSTOCK_ITEM
    {
        private string _StockName;
        private string _AreaName;
        private string _FloorName;
        private string _StoreName;
        private string _UnitName1;
        private string _UnitName2;
        private string _BarCode;
        private string _ProductCode;
        private string _Standard;
        private string _LotNumber;
        private string _SubLotNumber;
        private DateTime _Instock_Date;
        private string _KeyStandard;
        private string _SupplyLotNumber;
        private string _BigClass;
        private string _ClientName;

        public string StockName
        {
            get { return _StockName; }
            set { _StockName = value; }
        }
        public string AreaName
        {
            get { return this._AreaName; }
            set { this._AreaName = value; }
        }
        public string FloorName
        {
            get { return this._FloorName; }
            set { this._FloorName = value; }
        }
        public string StoreName
        {
            get { return this._StoreName; }
            set { this._StoreName = value; }
        }
        public string WeightUnitName
        {
            get { return this._UnitName1; }
            set { this._UnitName1 = value; }
        }
        public string PackUnitName
        {
            get { return this._UnitName2; }
            set
            {
                this._UnitName2 = value;
            }
        }
        public string BarCode
        {
            get { return _BarCode; }
            set { this._BarCode = value; }
        }

        public string ProductCode
        {
            get { return this._ProductCode; }
            set
            {
                this._ProductCode = value;
            }
        }

        public string Standard
        {
            get { return this._Standard; }
            set
            {
                this._Standard = value;
            }
        }

        public string LotNumber
        {
            get { return this._LotNumber; }
            set
            {
                this._LotNumber = value;
            }
        }

        public string SubLotNumber
        {
            get { return this._SubLotNumber; }
            set
            {
                this._SubLotNumber = value;
            }
        }
        public DateTime Instock_Date
        {
            get { return this._Instock_Date; }
            set { this._Instock_Date = value; }
        }
        public string KeyStandard
        {
            get { return this._KeyStandard; }
            set { this._KeyStandard = value; }
        }

        public string SupplyLotNumber
        {
            get { return this._SupplyLotNumber; }
            set { this._SupplyLotNumber = value; }
        }

        public string BigClass
        {
            get { return this._BigClass; }
            set { this._BigClass = value; }
        }

        public string ClientName
        {
            get
            {
                return _ClientName;
            }
            set
            {
                _ClientName = value;
            }
        }

        public string Size
        {
            get;
            set;
        }
    }
    public class VOutStock : T_OUTSTOCK
    {
        private string _ClientName;
        private string _CreateUserName;
        private string _AuditUserName;
        private string _TypeName;
        private string _ClinetCode;
        private string _remark;
        public string ClientName
        {
            get
            {
                return _ClientName;
            }
            set
            {
                _ClientName = value;
            }
        }
        public string Remark
        {
            get { return this._remark; }
            set { this._remark = value; }
        }
        public string CreateUserName
        {
            get { return _CreateUserName; }
            set
            {
                _CreateUserName = value;
            }
        }
        public string AuditUserName
        {
            get { return _AuditUserName; }
            set { _AuditUserName = value; }
        }
        public string ClinetCode
        {
            get { return this._ClinetCode; }
            set { this._ClinetCode = value; }
        }
        public string TypeName
        {
            get
            {
                return Enum.GetName(typeof(Enumerations.InStockType), this.TYPE);
            }
        }
    }

    public class OutStockReportBLL : BaseBLL
    {
        public VOutStock GetVOutstockByID(string ID)
        {
            T_OUTSTOCK source = new BaseDAO().T_OUTSTOCKs.Single(t => t.ID.ToString() == ID);
            if (source == null) return null;
            VOutStock vstock = new VOutStock();
            vstock.AUDIT_TIME = source.AUDIT_TIME;
            vstock.AUDITOR_ID = source.AUDITOR_ID;
            vstock.CAR_NO = source.CAR_NO;
            vstock.CLIENT_ID = source.CLIENT_ID;
            vstock.CREATE_TIME = source.CREATE_TIME;
            vstock.CREATOR_ID = source.CREATOR_ID;
            vstock.ID = source.ID;
            vstock.OUTSTOCK_DATE = source.OUTSTOCK_DATE;
            vstock.OUTSTOCK_ID = source.OUTSTOCK_ID;
            vstock.SERIAL_NO = source.SERIAL_NO;
            vstock.STATUS = source.STATUS;
            vstock.TRADE = source.TRADE;
            vstock.TRANSFER = source.TRANSFER;
            vstock.TRANSFER_NO = source.TRANSFER_NO;
            vstock.TYPE = source.TYPE;
            vstock.ClientName = source.T_CLIENT.NAME;
            vstock.CreateUserName = source.T_SYS_USER.NAME;
            vstock.AuditUserName = source.T_SYS_USER1.NAME;
            return vstock;
        }


        public IEnumerable<VOutStock> GetVOutstock(string ID)
        {
            var source = from t in new BaseDAO().T_OUTSTOCKs
                         where t.ID.ToString() == ID
                         select new VOutStock
                         {
                             AUDIT_TIME = t.AUDIT_TIME,
                             AUDITOR_ID = t.AUDITOR_ID,
                             CAR_NO = t.CAR_NO,
                             CLIENT_ID = t.CLIENT_ID,
                             CREATE_TIME = t.CREATE_TIME,
                             CREATOR_ID = t.CREATOR_ID,
                             ID = t.ID,
                             OUTSTOCK_DATE = t.OUTSTOCK_DATE,
                             OUTSTOCK_ID = t.OUTSTOCK_ID,
                             SERIAL_NO = t.SERIAL_NO,
                             STATUS = t.STATUS,
                             TRADE = t.TRADE,
                             TRANSFER = t.TRANSFER,
                             TRANSFER_NO = t.TRANSFER_NO,
                             TYPE = t.TYPE,
                             ClientName = t.T_CLIENT.NAME,
                             ClinetCode=t.T_CLIENT.ClientCode,
                             CreateUserName = t.T_SYS_USER.NAME,
                             AuditUserName = t.T_SYS_USER1.NAME,
                             RawID=t.RawID,
                             APPLY_ID=t.APPLY_ID,
                             Remark=t.Remark
                         };
            return source;
        }
        public IEnumerable<VOutStockItem> GetVOutstockItem(string StockID)
        {
            var source = from t in new BaseDAO().T_OUTSTOCK_ITEMs
                         where t.OUTSTOCK_ID.Value.ToString() == StockID
                         select new VOutStockItem
                         {
                             AreaName = t.T_FLOOR.T_STOCK_AREA.AREA_NAME,
                             BarCode = t.T_PRODUCT_DETAIL.BAR_CODE,
                             OUTSTOCK_ID = t.OUTSTOCK_ID,
                             FLOOR_ID = t.FLOOR_ID,
                             FloorName = t.T_FLOOR.FloorName,
                             GROSS_WEIGHT = t.GROSS_WEIGHT,
                             ID = t.ID,
                             PRODUCT_DETAIL_ID = t.PRODUCT_DETAIL_ID,
                             NET_WEIGHT = t.NET_WEIGHT,
                             PACKET_QTY = t.PACKET_QTY,
                             PACKET_QTY2 = t.PACKET_QTY2,
                             PackUnitName = t.T_PRODUCT_DETAIL.T_PRODUCT.T_UNIT.NAME,
                             REMARK = t.REMARK,
                             StockName = t.T_FLOOR.T_STOCK_AREA.T_STOCK.STOCK_NAME,
                             StoreName = t.T_PRODUCT_DETAIL.T_PRODUCT.NAME,
                             WeightUnitName = t.T_PRODUCT_DETAIL.T_PRODUCT.T_UNIT1.NAME,
                             ProductCode = t.T_PRODUCT_DETAIL.T_PRODUCT.CODE,
                             Standard = t.T_PRODUCT_DETAIL.STANDARD,
                             LotNumber = t.T_PRODUCT_DETAIL.LOT_NUMBER,
                             SubLotNumber = t.T_PRODUCT_DETAIL.SUB_LOT_NUMBER,
                             Instock_Date=t.T_PRODUCT_DETAIL.InStock_Date==null?DateTime.Now:t.T_PRODUCT_DETAIL.InStock_Date.Value,
                             KeyStandard=t.T_PRODUCT_DETAIL.KeyStandard,
                             SupplyLotNumber = t.T_PRODUCT_DETAIL.SupplyLotNumber,
                             BigClass = t.T_PRODUCT_DETAIL.BigClass,
                             Size = t.T_PRODUCT_DETAIL.SIZE,
                             ClientName = t.T_OUTSTOCK.T_CLIENT.NAME
                         };
            return source;
        }

        public IEnumerable<VOutStockItemGroup> GetVOutstockItemNoFloor(string StockID)
        {
            var source = from t in new BaseDAO().T_OUTSTOCK_ITEMs
                         where t.OUTSTOCK_ID.Value.ToString() == StockID
                         group t by new
                         {
                             //BarCode = t.T_PRODUCT_DETAIL.BAR_CODE,
                             StoreName = t.T_PRODUCT_DETAIL.T_PRODUCT.NAME,
                             ProductCode = t.T_PRODUCT_DETAIL.T_PRODUCT.CODE,
                             Standard = t.T_PRODUCT_DETAIL.STANDARD,
                             LotNumber = t.T_PRODUCT_DETAIL.LOT_NUMBER,
                             SubLotNumber = t.T_PRODUCT_DETAIL.SUB_LOT_NUMBER,
                             KeyStandard = t.T_PRODUCT_DETAIL.KeyStandard,
                             SupplyLotNumber = t.T_PRODUCT_DETAIL.SupplyLotNumber,
                             BigClass = t.T_PRODUCT_DETAIL.BigClass,
                             WeightUnitName = t.T_PRODUCT_DETAIL.T_PRODUCT.T_UNIT1.NAME,
                             PackUnitName = t.T_PRODUCT_DETAIL.T_PRODUCT.T_UNIT.NAME

                         } into p
                         select new VOutStockItemGroup
                         {
                             //BarCode = p.Key.BarCode,
                             StoreName = p.Key.StoreName,
                             PACKET_QTYCount = p.Sum(t => t.PACKET_QTY),
                             PACKET_QTY2Count = p.Sum(t => t.PACKET_QTY2),
                             NET_WEIGHTCount = p.Sum(t => t.NET_WEIGHT),
                             GROSS_WEIGHTCount = p.Sum(t => t.GROSS_WEIGHT),
                             ProductCode = p.Key.ProductCode,
                             Standard = p.Key.Standard,
                             LotNumber = p.Key.LotNumber,
                             SubLotNumber = p.Key.SubLotNumber,
                             KeyStandard = p.Key.KeyStandard,
                             SupplyLotNumber = p.Key.SupplyLotNumber,
                             BigClass = p.Key.BigClass,
                             WeightUnitName=p.Key.WeightUnitName,
                             PackUnitName=p.Key.PackUnitName                             
                         };
            return source;
        }
    }
}
